package com.itboye.system.crypt;

import java.io.*;
import java.util.Base64;

/**
 * Created by hebidu on 16/7/20.
 */
@SuppressWarnings("Since15")
public class Base64Crypt {


    /**
     * base64解密
     * @param encodeStr
     * @param charsetName
     * @return
     * @throws UnsupportedEncodingException
     */
    public static String decode(String encodeStr) throws UnsupportedEncodingException {

        Base64.Decoder decoder =  Base64.getMimeDecoder();
        byte[] decodeBytes = decoder.decode(encodeStr);

        return new String(decodeBytes,"utf-8");
    }

    /**
     * base64 编码
     * @param originStr
     * @return
     * @throws UnsupportedEncodingException
     */
    public static String encode(String originStr) throws UnsupportedEncodingException {
        Base64.Encoder encode = Base64.getEncoder();

        byte[] encodeBytes = encode.encode(originStr.getBytes("UTF-8"));

        return new String(encodeBytes,"UTF-8");
    }


}
